package com.tenement.utils.base;

import java.util.Random;

/**
 * 随机产生7位数字和字母组合
 * 
 * @author wk
 *
 */
public class StringRandom {
	
	/**
	 * 随机生成7个长度的字符串
	 * @return
	 */
	public static String getStringRandom() {
		String val = "";
		Random random = new Random();
		for (int i = 0; i < 7; i++) {

			String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
			// 输出字母还是数字
			if ("char".equalsIgnoreCase(charOrNum)) {
				// 输出是大写字母还是小写字母
				int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
				val += (char) (random.nextInt(26) + temp);
			} else if ("num".equalsIgnoreCase(charOrNum)) {
				val += String.valueOf(random.nextInt(10));
			}
		}
		return val.toLowerCase();
	}
	
	public static void main(String[] args) {
		System.out.println(getStringRandom());
	}
}
